;
(function() {
	var ResponObj = require("../_include/responObj");
	var ShortCon = require("../../core/short/_con");
	var wx_v2 = require("../../my_modules/wx/wx.v2").dotnar_instance;
	module.exports = {
		prefix: "/s",
		get: {
			"/:hash": function(argument) {
				var short_obj = ShortCon.get(this.params.hash);
				if (short_obj) {
					//302重定向
					this.response.status(302)
					this.response.header("Location", short_obj.value);
					this.body = "";
					// this.body = ResponObj("refresh", short_obj.value);
				} else {
					this.response.send(500, "err hash:" + this.params.hash);
				}
			}
		},
		post: {
			"/": function() {
				var body = this.request.body;
				var url = body.url;
				var short_obj = new ShortCon(url);
				this.body = ResponObj("json", short_obj._id);
			},
			"/wx": function() {
				var body = this.request.body;
				var url = body.url;
				this.body = ResponObj("string", wx_v2.shortUrl(url));
			}
		},
		put: {
			"/:hash": function() {
				var short_obj = ShortCon.get(this.params.hash);
				var body = this.request.body;
				var url = body.url;
				short_obj.changeValue(url);
				this.body = short_obj.toUrl();
			}
		}
	}
}());